package com.lianniu.mgr.cms.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.cms.model.HelpCenterInfoVo;
import com.lianniu.mgr.cms.service.IHelpCenterInfoService;
import com.lianniu.mgr.pagination.PaginationInfo;


@Controller
@RequestMapping("/rest/HelpCenterInfo")
public class HelpCenterInfoRestController {
	private final static Logger logger = Logger.getLogger(HelpCenterInfoRestController.class);
	
	@Autowired
	private IHelpCenterInfoService helpCenterInfoService;
	
	@RequestMapping(value="/HelpCenterInfoList",method={RequestMethod.GET,RequestMethod.POST})
	public @ResponseBody BaseResult HelpCenterInfoList(HttpServletRequest request, HelpCenterInfoVo curVo, PaginationInfo paginationInfo)
	 {
	       logger.info("HelpCenterInfoRestController  HelpCenterInfoList begin.");
	       try {
	           
	           logger.info("HelpCenterInfoList begin.");          
	           BaseResult baseResult = helpCenterInfoService.selectByHelpCenterInfoForPage(curVo, paginationInfo);
	           logger.info("HelpCenterInfoList end.");
	           logger.info("HelpCenterInfoRestController HelpCenterInfoList end.");
	           return baseResult;
	       } catch (Exception e) {
	       logger.error("HelpCenterInfoRestController HelpCenterInfoList error:" + e.getMessage());
	       logger.error("HelpCenterInfoRestController HelpCenterInfoList end.");
	       return BaseResult.exception(e.getMessage());
	     }
	  }
	
	@RequestMapping(value = {"/HelpCenterInfoAdd"}, method = RequestMethod.POST)
	public @ResponseBody BaseResult helpCenterInfoAdd(HttpServletRequest request,HelpCenterInfoVo curVo) {
	      logger.info("HelpCenterInfoRestController HelpCenterInfoAdd begin.");      
	      logger.info("HelpCenterInfoRestController HelpCenterInfoAdd:"+ JSON.toJSONString(curVo));
	      try {
	          logger.info("ProductBrandAdd begin.");
	        
	          BaseResult baseResult = helpCenterInfoService.insertHelpCenterInfo(curVo);
	          logger.info("ProductBrandAdd baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("ProductBrandAdd end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("ProductBrandAdd error:"+e.getMessage());
	      logger.info("HelpCenterInfoRestController HelpCenterInfoAdd end.");
	      return BaseResult.exception(e.getMessage());
	    }

	  }
	
	 
	@RequestMapping(value = {"/HelpCenterInfoEdit"}, method = RequestMethod.POST)
	  public @ResponseBody BaseResult HelpCenterInfoEdit(HttpServletRequest request,HelpCenterInfoVo curVo) {
	      logger.info("HelpCenterInfoRestController HelpCenterInfoEdit begin.");      
	      logger.info("HelpCenterInfoRestController HelpCenterInfoEdit:"+ JSON.toJSONString(curVo));
	      try {
	          logger.info("HelpCenterInfoEdit begin.");
	          BaseResult baseResult = helpCenterInfoService.updateById(curVo);
	          logger.info("HelpCenterInfoEdit baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("HelpCenterInfoEdit end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("HelpCenterInfoRestController error:"+e.getMessage());
	      logger.info("HelpCenterInfoRestController HelpCenterInfoEdit end.");
	      return BaseResult.exception(e.getMessage());
	    }
	  }
	  
	
	 @RequestMapping(value="/selectHelpCenterInfoById",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult selectHelpCenterInfoById(HttpServletRequest request,HelpCenterInfoVo curVo) {
	        logger.info("HelpCenterInfoRestController selectHelpCenterInfoById begin.");
	        try {
	                    
	          BaseResult baseResult = helpCenterInfoService.selectById(curVo);
	          logger.info("HelpCenterInfoRestController end.");
	          logger.info("HelpCenterInfoRestController selectHelpCenterInfoById end.");
	          return baseResult;
	        } catch (Exception e) {
	          logger.error("HelpCenterInfoRestController selectHelpCenterInfoById error:" + e.getMessage());
	          logger.error("HelpCenterInfoRestController selectHelpCenterInfoById end.");
	          return BaseResult.exception(e.getMessage());
	        }
	  } 
	 
	 @RequestMapping(value = {"/HelpCenterInfoDel"}, method = RequestMethod.POST)
	  public @ResponseBody BaseResult HelpCenterInfoDel(HttpServletRequest request) {
	      logger.info("HelpCenterInfoRestController HelpCenterInfoDel begin.");
	     try {          
	          logger.info("HelpCenterInfoDel begin.");
	          BaseResult baseResult = helpCenterInfoService.deleteHelpCenterInfoBatch(request.getParameter("ids").split(","));		
	          logger.info("HelpCenterInfoDel baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("HelpCenterInfoDel end.");
	          
	          logger.info("HelpCenterInfoRestController HelpCenterInfoDel end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("HelpCenterInfoRestController HelpCenterInfoDel error:" + e.getMessage());
	      logger.info("HelpCenterInfoRestController HelpCenterInfoDel end.");
	      return BaseResult.exception(e.getMessage());
	    }

	  }
	 
	 @RequestMapping(value = {"/checkTitle"}, method = RequestMethod.POST)
	  public @ResponseBody Boolean checkTitle(HttpServletRequest request) {
	      Boolean flag=true;
	      String parentId=  request.getParameter("parentId");
	      String title=  request.getParameter("title");
	      logger.info("HelpCenterInfoRestController checkTitle begin.");
	     try {          
	          logger.info("checkTitle begin.");
	          if("".equalsIgnoreCase(title)||title==null)
	          {return flag;}
	          flag = helpCenterInfoService.checkTitle(title,parentId);         
	          logger.info("checkTitle end.");
	          
	          logger.info("HelpCenterInfoRestController checkTitle end.");
	          return flag;
	    } catch (Exception e) {
	      logger.error("HelpCenterInfoRestController checkTitle error:" + e.getMessage());
	      logger.info("HelpCenterInfoRestController checkTitle end.");
	      return flag;
	    }

	  }
	 
	 @RequestMapping(value = {"/checkTitleEdit"}, method = RequestMethod.POST)
	  public @ResponseBody Boolean checkTitleEdit(HttpServletRequest request) {
	      Boolean flag=true;
	      String title=  request.getParameter("title");
	      String parentId=  request.getParameter("parentId");
	      String id=request.getParameter("id");
	      logger.info("HelpCenterInfoRestController checkTitleEdit begin.");
	     try {          
	          logger.info("checkTitleEdit begin.");
	          HelpCenterInfoVo vo=new HelpCenterInfoVo();	         
	          vo.setId(id);
	          
	          BaseResult baseResult =helpCenterInfoService.selectById(vo);	          
	          HelpCenterInfoVo curVo=(HelpCenterInfoVo) baseResult.getData();
	          if(curVo.getId().equals(id)&&curVo.getTitle().equals(title))
	          {return flag;}
	          if("".equalsIgnoreCase(title)||title==null)
	          {return flag;}
	          flag = helpCenterInfoService.checkTitle(title,parentId);         
	          logger.info("checkTitleEdit end.");
	          
	          logger.info("HelpCenterInfoRestController checkTitleEdit end.");
	          return flag;
	    } catch (Exception e) {
	      logger.error("HelpCenterInfoRestController checkTitleEdit error:" + e.getMessage());
	      logger.info("HelpCenterInfoRestController checkTitleEdit end.");
	      return flag;
	    }

	  }
	
	
}
